-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: custom exception handler #6710
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a big one, I will have to come back to it! Initially it looks really good. Please be sure to work with @lonnieezell for feature consistency and @paulbalandan if there's any collaboration to be had with the deprecations handler PR.
I'll be honest - this week I'm completely wrecked for time so I won't be able to really review until next week. That said - the reason nothing happened with the original one was because it was a BC break and would have to wait until v5. Has the BC break portion been fixed with this PR? |
No problem. The original PR was created many months ago. I have tried to keep this PR free of BC breaks. |
b22c181
to
2017313
Compare
Rebased. |
af3f99e
to
9db24aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at docs and tests yet, but this is looking great! I added some comments but two broad thoughts:
- It seems like the new classes are independent of the existing ones, and you use the current handle as a mediator to call them when available. I like the freedom that gives us - but then you kept ExceptionHandler compatible with the current class. It don't understand the need for this backwards-compatibility, unless I am missing something?
- I know we've been burned by class-interface-abstraction, but enforcing our BaseExceptionHandler for a single
handle()
method feels unduly restrictive. I would like to see an interface (just that method) used as the return from the Config file and the abstract class becomes optional.
* | ||
* @return bool|string | ||
*/ | ||
protected static function highlightFile(string $file, int $lineNumber, int $lines = 15) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the existing handler doesn't actually extend this base, can we go ahead and type this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
system/Debug/Exceptions.php
Outdated
@@ -122,6 +125,23 @@ public function exceptionHandler(Throwable $exception) | |||
]); | |||
} | |||
|
|||
// For upgraded users. | |||
if (! method_exists($this->config, 'handler')) { | |||
$this->defaultExceptionHandler($exception, $statusCode, $exitCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't this use ExceptionHandler
? Is it not backwards-compatible behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
It should use ExceptionHandler.
When using ExceptionHandler, if the behavior changes it is a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/** | ||
* Determines the correct way to display the error. | ||
* | ||
* @return void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like a big loss not having this in the abstraction. Any reason not to do that?
9db24aa
to
b93407c
Compare
The section "Error Handling" has been added.
b93407c
to
9d5d44f
Compare
No. If a dev overrides the following methods, this PR breaks the extended Exceptions:
|
Reverting 9d5d44f and a dev does not update the Config class, |
I'm confused; I think I missed something. |
If we want to support extended classes just check |
The new classes do not need to be backwards-compatible with Exceptions. A dev can replace Exceptions with their custom extended class now, and if the dev overrides one of some methods,
It may be Okay with that check, as a dev would not need to use their own ExceptionHandler and replace Exceptions at the same time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me. I just found one edge case that we don't handle.
$viewFile = null; | ||
if (is_file($path . $view)) { | ||
$viewFile = $path . $view; | ||
} elseif (is_file($altPath . $altView)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we need to handle if neither file exists?
Since this is the case please add explicit types to all the new class methods. I am also still keen on adding an interface - nothing else in the base class is mandatory so we shouldn't restrict users to extending it. |
Description
Supersedes #5675
Checklist: